//
//  OffcialTableViewCell.m
//  QuickReadComic
//
//  Created by 苗钧豪 on 16/9/1.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "OffcialTableViewCell.h"
#import "OffcialCollectionViewCell.h"
#import "ZWYNetTool.h"
#import "UIImageView+WebCache.h"
#import "BannersModel.h"
@implementation OffcialTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self NetworkRequests];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    [layout setItemSize:CGSizeMake((self.bounds.size.width - 8) / 2, (self.bounds.size.height))];
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.minimumInteritemSpacing = 8;
    layout.minimumLineSpacing = 8;
    [self.offcialCollectionView setCollectionViewLayout:layout];
    [_offcialCollectionView registerNib:[UINib nibWithNibName:@"OffcialCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"offcial"];
    _offcialCollectionView.backgroundColor = [UIColor clearColor];
    _offcialCollectionView.bounces = NO;
    _offcialCollectionView.delegate = self;
    _offcialCollectionView.dataSource = self;
}
- (void)NetworkRequests {
    [ZWYNetTool GET:@"http://api.kuaikanmanhua.com/v1/topic_new/discovery_list?" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
        NSLog(@"=====================成功啦");
        self.model = [dataModel modelWithDic:result[@"data"]];
        [self.offcialCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
        NSLog(@"=====================出错啦");
    }];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    OffcialCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"offcial" forIndexPath:indexPath];
    BannersModel *banners = self.model.infos[self.Number].banners[indexPath.row];
    NSLog(@"\n\n\n%@",self.model.infos);
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",banners.pic]]];
    cell.titleLabel.text = banners.target_title;
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
